package modell;

import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import javax.swing.JApplet;
import javax.swing.JFrame;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.io.File;
import java.util.ArrayList;

import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.TextureLoader;
import javax.media.j3d.*;
import javax.vecmath.*;

import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;
import javax.vecmath.*;
import javax.media.j3d.Alpha.*;
import javax.media.j3d.PositionInterpolator.*;



public class Canon extends BranchGroup{
	
	BranchGroup rohr_bg;
	BranchGroup speichen_bg;
	BranchGroup raeder_bg;
	TransformGroup rohr_tg = new TransformGroup();
	TransformGroup speichen_tg = new TransformGroup();
	TransformGroup raeder_tg = new TransformGroup();
	
	public Canon(){
		try{
			rohr_bg = ObjLoader.load("./objects/kanone_rohr.obj");
			rohr_tg.addChild(rohr_bg);
			speichen_bg = ObjLoader.load("./objects/kanone_speichen.obj");
			speichen_tg.addChild(speichen_bg);
			raeder_bg = ObjLoader.load("./objects/kanone_raeder.obj");
			raeder_tg.addChild(raeder_bg);
		} catch (Throwable t) {
			System.err.println("Objects could not be loaded: "+t.toString());
		}
		
		// Move single objects to fit together.
		Transform3D translation = new Transform3D();
		translation.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
		rohr_tg.setTransform(translation);
		translation.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
		speichen_tg.setTransform(translation);
		translation.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
		raeder_tg.setTransform(translation);
		
		// Add appearance to single objects.
		Appearance rohr_ap = new Appearance();
		rohr_ap.setMaterial(new Material(new Color3f(0.0f, 0.0f, 0.0f), 
				new Color3f(0.0f, 0.0f, 0.0f), 
				new Color3f(0.2f, 0.2f, 0.2f), 
				new Color3f(1.0f, 1.0f, 1.0f), 0.6f));
		Shape3D rohr_shape = ObjLoader.getShape3D(rohr_bg);
		rohr_shape.setAppearance(rohr_ap);
		
		Appearance speichen_ap = new Appearance();
		speichen_ap.setMaterial(new Material(new Color3f(0.0f, 0.0f, 0.0f), 
				new Color3f(0.0f, 0.0f, 0.0f), 
				new Color3f(0.62f, 0.32f, 0.0f), 
				new Color3f(1.0f, 0.5f, 0.0f), 0.1f));
		Shape3D speichen_shape = ObjLoader.getShape3D(speichen_bg);
		speichen_shape.setAppearance(speichen_ap);
		
		Appearance raeder_ap = new Appearance();
		raeder_ap.setMaterial(new Material(new Color3f(1.0f, 1.0f, 1.0f), 
				new Color3f(0.0f, 0.0f, 0.0f), 
				new Color3f(1.0f, 1.0f, 1.0f), 
				new Color3f(1.0f, 1.0f, 1.0f), 0.2f));
		Shape3D raeder_shape = ObjLoader.getShape3D(raeder_bg);
		raeder_shape.setAppearance(raeder_ap);
		
		//Ausrichtung der Kanone
		Transform3D canonRotation = new Transform3D();
		canonRotation.rotY(Math.PI);
		rohr_tg.setTransform(canonRotation);
		speichen_tg.setTransform(canonRotation);
		raeder_tg.setTransform(canonRotation);
		
		this.addChild(rohr_tg);
		this.addChild(speichen_tg);
		this.addChild(raeder_tg);
	}
}
